package com.supermarket.seefood51.home.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.OrientationHelper
import com.supermarket.seefood51.R
import com.supermarket.seefood51.base.BaseFragment
import com.supermarket.seefood51.component.DaggerCarComponent
import com.supermarket.seefood51.component.DaggerLoginComponent
import com.supermarket.seefood51.entity.SeaFoodEntity
import com.supermarket.seefood51.home.CartAdapter
import com.supermarket.seefood51.home.ProductAdapter
import com.supermarket.seefood51.home.model.CartInjectModel
import com.supermarket.seefood51.home.model.ProductInjectModel
import com.supermarket.seefood51.home.view.CarView
import com.supermarket.seefood51.login.LoginActivity
import kotlinx.android.synthetic.main.fragment_cart.*


class CartFragment : BaseFragment(),CarView {
    override fun addCart(t: SeaFoodEntity) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun notifyDataChange(list: List<SeaFoodEntity>) {

    }


    companion object {

        val ARG_PARAM1 = "param1"
        val ARG_PARAM2 = "param2"
        fun newInstance(param1: String, param2: String): CartFragment {
            val fragment = CartFragment()
            val args = Bundle()
            args.putString(ARG_PARAM1, param1)
            args.putString(ARG_PARAM2, param2)
            fragment.arguments = args
            return fragment
        }
    }

    lateinit var cartAdapter: CartAdapter

    override fun initView() {


        var layoutManager = LinearLayoutManager(activity)
//设置布局管理器
        recyclerView.layoutManager = layoutManager

//设置为垂直布局，这也是默认的
        layoutManager.orientation = OrientationHelper.VERTICAL
//设置Adapter
        recyclerView.adapter = cartAdapter
//        //设置分隔线
//        recyclerView.addItemDecoration( DividerGridItemDecoration (this))
//设置增加或删除条目的动画
        recyclerView.itemAnimator = DefaultItemAnimator()


        DaggerCarComponent.builder().cartInjectModel(CartInjectModel(activity, this))
                .build().inject(this)
        exit.setOnClickListener {
            var intent = Intent(activity, LoginActivity::class.java)
            startActivity(intent)
        }


    }

    override fun getViewRoot(): Int {
        return R.layout.fragment_cart
    }

}
